<?php

define('IN_API', true);
require_once '../../framework/bootstrap.inc.php';
require_once 'defines.php';
$id = $_GPC['xcxid'];
$lyid = $_GPC['lyid'];
$pwd = $_GPC['pwd'];
$settings = pdo_get("uni_account_modules", array("module" => MODULE_NAME , "uniacid" => $id));
$settings = unserialize($settings['settings']);
if($pwd != $settings['pwd']){
    echo '密码不正确</br>';
	exit();
}

$condition = " WHERE uniacid = ".$id;
$orderby = " ORDER BY user_id ASC ";
$list = pdo_fetchall("SELECT * FROM " . tablename(MODULE_NAME."_user") . $condition . $orderby);

foreach ($list as $key => $val) {
	$res = pdo_update(MODULE_NAME."_user", array('system_id' => $lyid), array("user_id" => $val['user_id'],"uniacid" => $id));
}

echo '用户迁移完毕</br>';

$condition = " WHERE uniacid = ".$id;
$orderby = " ORDER BY id ASC ";
$list = pdo_fetchall("SELECT * FROM " . tablename(MODULE_NAME."_order") . $condition . $orderby);
foreach ($list as $key => $val) {
	pdo_delete(MODULE_NAME.'_order_u', array('order_id' => $val['order_id']));
	unset($val['id']);
	$val['system_id'] = $lyid;
	$result = pdo_insert(MODULE_NAME."_order_u", $val);	
}
echo '订单迁移完毕</br>';

$condition = " WHERE uniacid = ".$id;
$orderby = " ORDER BY id ASC ";
$list = pdo_fetchall("SELECT * FROM " . tablename(MODULE_NAME."_pid") . $condition . $orderby);
foreach ($list as $key => $val) {
	pdo_delete(MODULE_NAME.'_pid_u', array('pid' => $val['pid']));
	unset($val['id']);
	$val['system_id'] = $lyid;
	$result = pdo_insert(MODULE_NAME."_pid_u", $val);	
}
echo 'PID迁移完毕</br>';
